<template>
	<view>
		<view class="header">
			<view class="integral_info">
				<view class="navbar">
					<view class="navbar-fixed">
						<!-- 状态栏小程序撑起高度 -->
						<view :style="{ height: statusBarHeight + 'px' }"></view>
						<view class="navbar-content" :style="{ height: navBarHeight + 'px', width: windowWidth + 'px' }">
							<image src="../../static/jt6.png" @click="back()"></image>
							<view class="navbar-search">我的积分</view>
						</view>
					</view>
					<!-- 需要添加占位符高度  状态栏高度+导航栏高度（否则下面tab会塌陷）indexOf-->
					<view :style="{ height: statusBarHeight + navBarHeight + 'px' }"></view>
				</view>
				<view class="scoreinfo">
					<view class="num">积分余额</view>
					<view class="but" @click="tomoney()">{{ parseFloat(this.myinfo.integral) || 0 }}</view>
				</view>
			</view>
		</view>
		<!-- <view style="height: 380rpx;"></view> -->
		<view class="scorebox">
			<view class="titbox">充值积分</view>
			<view class="listbox">
				<view class="itembox" v-for="(item, index) in list" :key="index" @click="changcurrone(item, index)">
					<view class="listitem" :style="{ border: index == currone ? '2rpx solid #FF7E91' : none, background: index == currone ? '#FFF' : '#F7F7F7' }">
						<view :style="{ color: index == currone ? '#FF6178' : '#222' }" class="money">{{ item.score }}积分</view>
						<view :style="{ color: index == currone ? '#FF6178' : '#555555' }">￥{{ item.money }}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="butbox" @click="submit()">立即充值</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			statusBarHeight: 20,
			/* 状态栏高度 */
			navBarHeight: 45,
			/* 导航栏高度 */
			windowWidth: 375,
			/* 窗口宽度 */
			/* 设定状态栏默认高度 */
			currone: 0,
			list: [],
			cate_id: "",
			myinfo: {},
			money: "",
		}
	},
	onShow() {
		this.getnav()
	},
	onLoad() {
		this.getmyinfo()
		this.getlist()
	},
	methods: {
		getnav() {
			// 获取手机系统信息
			const info = uni.getSystemInfoSync()
			// 设置状态栏高度（H5顶部无状态栏小程序有状态栏需要撑起高度）
			this.statusBarHeight = info.statusBarHeight
			this.windowWidth = info.windowWidth
			// 除了h5 app mp-alipay的情况下执行
			// #ifndef H5 || APP-PLUS || MP-ALIPAY
			// 获取胶囊的位置
			const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
			console.log(menuButtonInfo)
			// (胶囊底部高度 - 状态栏的高度) + (胶囊顶部高度 - 状态栏内的高度) = 导航栏的高度
			this.navBarHeight = menuButtonInfo.bottom - info.statusBarHeight + (menuButtonInfo.top - info.statusBarHeight)
			this.windowWidth = menuButtonInfo.left
			// #endif
		},
		back() {
			uni.navigateBack({
				delta: 1,
			})
		},
		getmyinfo() {
			this.$http({
				url: "/api/Course/user_info",
			}).then((res) => {
				this.myinfo = res.data
				//identity 1普通用户2志愿者3老师
			})
		},
		changcurrone(item, index) {
			this.currone = index
			this.money = item.money
		},
		todetail(item) {
			uni.navigateTo({
				url: "/pageshop/goodsinfo/goodsinfo?id=" + item.id,
			})
		},
		getlist() {
			this.$http({
				url: "/api/Activity/recharge_list",
			}).then((res) => {
				this.list = res.data
			})
		},
		// submit(){
		// 	this.$http({
		// 		url:'/api/Activity/score_recharge',
		// 		data:{
		// 			money:this.money||this.list[this.currone].money,
		// 		}
		// 	}).then(res=>{
		// 		uni.showToast({
		// 			title:res.msg,
		// 			icon:'none'
		// 		})
		// 	})
		// }
		async submit(orderid) {
			const { data } = await this.$http({
				url: "/api/Activity/score_recharge",
				data: {
					money: this.money || this.list[this.currone].money,
				},
			})
			let that = this

			uni.requestPayment({
				timeStamp: data.timeStamp,
				nonceStr: data.nonceStr,
				package: data.package,
				signType: "MD5",
				paySign: data.paySign,
				success: function (res) {
					uni.showToast({
						title: "支付成功",
						icon: "none",
					})
					setTimeout(() => {
						uni.navigateBack({
							delta: 1,
						})
					}, 1000)
				},
				fail: function (res) {
					uni.showToast({
						title: "支付失败",
						icon: "none",
					})
				},
			})
		},
	},
}
</script>

<style lang="scss" scoped>
.header {
	// position: fixed;
	// top: 0;
	width: 750rpx;
	// z-index: 999;
	.integral_info {
		width: 750rpx;
		height: 380rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		color: #ffffff;
		background-image: url($uni-url + "/bg9.png");
		background-size: 100% 100%;
		margin: 0 auto;

		.navbar {
			.navbar-fixed {
				position: fixed;
				top: 0;
				left: 0;
				z-index: 399;
				width: 100%;
				// height: 102rpx;
				// padding-bottom: 20rpx;
				background: transparent;

				.navbar-content {
					display: flex;
					// justify-content: center;
					align-items: center;
					padding: 0rpx 30rpx;
					// height: 142rpx;
					box-sizing: border-box;

					image {
						width: 44rpx;
						height: 44rpx;
						margin-right: 20rpx;
					}

					.navbar-search {
						display: flex;
						// align-items: center;
						// padding: 0 10px;
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #222;
						// position: absolute;
						// left: 50%;
						// transform: translate(-50%,0);
					}
				}
			}
		}
		.scoreinfo {
			// display: flex;
			// align-items: center;
			height: 350rpx;
			width: 650rpx;
			text-align: center;
			// justify-content: space-between;
			margin: 0 auto;
			.num {
				font-size: 28rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #222222;
				margin: 30rpx 0;
			}
			.but {
				font-size: 56rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #222222;
			}
		}
	}
	.navlist {
		display: flex;
		align-items: center;
		background-color: #fff;
		height: 122rpx;
		border-radius: 22rpx 22rpx 0 0;
		margin-top: -22rpx;
		width: 750rpx;
		.swiperbox {
			width: 628rpx;
			display: flex;
			align-items: center;
			.scroll-view_H {
				white-space: nowrap;
				width: 100%;
				.scroll-view-item_H {
					display: inline-block;
					width: fit-content;
					padding: 0 20rpx;
					height: 122rpx;
					// line-height: 122rpx;

					> view {
						line-height: 122rpx;
						text-align: center;
						font-size: 30rpx;
						font-family: SourceHanSansCN-Medium-, SourceHanSansCN-Medium;
						font-weight: normal;
						color: #222;
					}
				}
			}
		}
		.allcate {
			width: 128rpx;
			height: 122rpx;
			display: flex;
			align-items: center;
			font-size: 30rpx;
			font-family: Source Han Sans CN-Medium, Source Han Sans CN;
			font-weight: 500;
			color: #555555;
			image {
				width: 26rpx;
				height: 27rpx;
				margin-left: 6rpx;
			}
		}
	}
}
.tiptype {
	width: 100%;
	padding-top: 472rpx;
	background-color: #fff;

	.boxitem {
		display: flex;
		flex-wrap: wrap;
		width: 690rpx;
		padding: 40rpx 30rpx;

		.itembox {
			height: 72rpx;
			border-radius: 40rpx;
			border: 2rpx solid #999999;
			line-height: 72rpx;
			width: fit-content;
			padding: 0 50rpx;
			margin-right: 24rpx;
			margin-bottom: 20rpx;
		}
	}
}
.scorebox {
	background-color: #fff;
	width: 690rpx;
	padding: 0 30rpx 20rpx 30rpx;
	margin-top: -20rpx;
	border-radius: 20rpx;
	.titbox {
		height: 108rpx;
		line-height: 108rpx;
		font-size: 28rpx;
		font-family: Source Han Sans CN-Medium, Source Han Sans CN;
		font-weight: 500;
		color: #222222;
		width: 690rpx;
	}
	.listbox {
		display: flex;
		flex-wrap: wrap;
		width: 690rpx;
		// justify-content: space-between;
		.itembox {
			width: 33.3%;
			.listitem {
				width: 90%;
				margin: 0 auto 18rpx auto;
				text-align: center;
				height: 124rpx;
				border-radius: 18rpx;
				border: solid 2rpx #f7f7f7;
				background: #f7f7f7;
				font-size: 28rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #222222;
				.money {
					font-size: 32rpx;
					font-family: Source Han Sans CN-Medium, Source Han Sans CN;
					font-weight: 500;
					color: #222222;
					padding: 15rpx 0;
				}
			}
		}
	}
}
.butbox {
	width: 690rpx;
	height: 96rpx;
	background: #ff8a9b;
	border-radius: 83rpx;
	text-align: center;
	line-height: 96rpx;
	color: #fff;
	margin: 120rpx auto;
}
</style>
